from manim import *
from numpy import flip, insert

LV,QL,QH,JH='#75cfb8','#bbdfc8','#f0e5d8','#ffc478'

class p1(MovingCameraScene):
    def construct(self):
        # self.add(NumberPlane())
        # self.camera.frame.scale(0.5)
        # x^2+y^2=r^2 6,8,10
        x=ValueTracker(50)
        r=5
        diam=Line(LEFT*r,RIGHT*r).shift(DOWN*r/2)
        o=diam.get_center()
        arc=Arc(r,0,PI,arc_center=o)
        p=diam.point_from_proportion(0.3)
        arc90=Arc(r,x.get_value()*DEGREES,PI/2,arc_center=o)
        m,n=arc90.get_boundary_point(LEFT),arc90.get_boundary_point(RIGHT)
        square_m,square_n=Square(m[1]+r/2).set_fill(LV,1).next_to(m,DR,buff=0),Square(n[1]+r/2).set_fill(JH,1).next_to(n,DL,buff=0)
        b10=Brace(diam,DOWN)
        self.add(diam,arc,square_m,square_n,b10,
            MathTex('10').next_to(b10,DOWN))
        self.wait()

class p2(MovingCameraScene):
    def construct(self):
        # self.add(NumberPlane())
        # self.camera.frame.scale(0.5)
        # x^2+y^2=r^2 6,8,10
        x=ValueTracker(50)
        r=5
        diam=Line(LEFT*r,RIGHT*r).shift(DOWN*r/2)
        o=diam.get_center()
        arc=Arc(r,0,PI,arc_center=o)
        p=diam.point_from_proportion(0.3)
        arc90=Arc(r,x.get_value()*DEGREES,PI/2,arc_center=o)
        m,n=arc90.get_boundary_point(LEFT),arc90.get_boundary_point(RIGHT)
        square_m,square_n=Square(m[1]+r/2).set_fill(LV,1).next_to(m,DR,buff=0),Square(n[1]+r/2).set_fill(JH,1).next_to(n,DL,buff=0)
        self.add(diam,arc,square_m,square_n)
        # p2
        p=m+DR*(m[1]+r/2)
        a,b=square_m.get_boundary_point(UL),square_n.get_boundary_point(UR)
        ab,pa,pb=Line(a,b),Line(p,a),Line(p,b)
        self.add(ab,pa,pb,
            MathTex('P').next_to(p,DOWN),
            MathTex('A').next_to(a,UL),
            MathTex('B').next_to(b,UR),
            MathTex('x').next_to(square_m,DOWN),
            MathTex('y').next_to(square_n,DOWN),
        )
        self.wait()

class p3(MovingCameraScene):
    def construct(self):
        # self.add(NumberPlane())
        # self.camera.frame.scale(0.5)
        # x^2+y^2=r^2 6,8,10
        x=ValueTracker(50)
        r=3
        diam=Line(LEFT*r,RIGHT*r)
        o=diam.get_center()
        arc=Arc(r,0,PI,arc_center=o)
        p=diam.point_from_proportion(0.3)
        arc90=Arc(r,x.get_value()*DEGREES,PI/2,arc_center=o)
        m,n=arc90.get_boundary_point(LEFT),arc90.get_boundary_point(RIGHT)
        square_m,square_n=Square(m[1]).set_fill(LV,1).next_to(m,DR,buff=0),Square(n[1]).set_fill(JH,1).next_to(n,DL,buff=0)
        # p2
        p=m+DR*(m[1])
        a,b=square_m.get_boundary_point(UL),square_n.get_boundary_point(UR)
        pa,pb=Line(p,a),Line(p,b)
        up=VGroup(diam,arc,square_m,square_n,pa,pb)
        self.add(up,up.copy().rotate(PI,[1,0,0],about_point=ORIGIN),Dot(o),Line(o,a),Line(o,b),Line(a,b),
            MathTex('O').next_to(o,DR),
            MathTex('A').next_to(a,UL),
            MathTex('B').next_to(b,UR),
            MathTex('A^\prime').next_to(a,DL).shift(DOWN*m[1]*2),
            MathTex('B^\prime').next_to(b,DR).shift(DOWN*n[1]*2),
        )
        self.wait()